<template>
  <view 
    class="game-grid"
    :style="{
      gridTemplateColumns: `repeat(${gridSize}, ${cellSize}rpx)`,
      gap: '2rpx'
    }"
  >
    <view 
      v-for="(row, y) in grid" 
      :key="y"
    >
      <view 
        v-for="(color, x) in row" 
        :key="x"
        class="grid-cell"
        :style="{
          width: `${cellSize}rpx`,
          height: `${cellSize}rpx`,
          backgroundColor: color,
        }"
        :class="{ 'selected': x === selectedCell.x && y === selectedCell.y }"
        @click="$emit('cell-click', x, y)"
      ></view>
    </view>
  </view>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  grid: {
    type: Array,
    required: true
  },
  selectedCell: {
    type: Object,
    default: () => ({ x: 0, y: 0 })
  },
  cellSize: {
    type: Number,
    default: 60
  }
})

const gridSize = computed(() => {
  return props.grid.length
})
</script>

<style scoped>
.game-grid {
  display: grid;
  padding: 16rpx;
  background-color: #222;
  border-radius: 8rpx;
}

.grid-cell {
  border-radius: 4rpx;
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
  background-clip: padding-box;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    0 2px 4px rgba(0, 0, 0, 0.15);
}

.grid-cell::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  height: 50%;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 0 0 100% 0;
  transition: opacity 0.3s;
}

.grid-cell.selected {
  border: 2rpx solid #FD79A8;
  transform: scale(1.05);
  z-index: 10;
  box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.2);
}

.grid-cell.selected::before {
  background-color: rgba(255, 255, 255, 0.2);
}
</style>